package com.caption.mq.entity;

import lombok.Data;

@Data
public class ModelResult<T> {
    private T data;
    private Integer code;
    private String msg;
    private Boolean isSuccess;

    public Boolean isSuccess() {
        return this.isSuccess;
    }

    public ModelResult successFactory(T t) {
        ModelResult result = new ModelResult();
        result.isSuccess = true;
        result.data = t;
        result.code = 0;
        return result;
    }

    public ModelResult failFactory(Integer code, String msg) {
        ModelResult result = new ModelResult();
        result.isSuccess = false;
        result.code = code;
        result.msg = msg;
        return result;
    }

    public ModelResult failFactory(String msg) {
        ModelResult result = new ModelResult();
        result.isSuccess = false;
        result.code = -1;
        result.msg = msg;
        return result;
    }

}
